package net.huashitong.synthetical.AddressBook.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.AddressBook.entity.AddressBook;
import net.huashitong.synthetical.AddressBook.filter.BookFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AddressBookDao extends StringDao<AddressBook> {

    public List<AddressBook> getBooks(BookFilter filter)
    {
        GenericQuery query  = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getDeptName()))
            query.append(" and obj.deptName like:deptName").setParam("deptName",filter.getDeptName());
        if(StringUtils.isNotBlank(filter.getDeptCode()))
            query.append(" and obj.deptCode=:deptCode ").setParam("deptCode",filter.getDeptCode());
        if(StringUtils.isNotBlank(filter.getDeptType()))
            query.append(" and obj.deptType =:deptType").setParam("deptType",filter.getDeptType());

        return  query.listResult();
    }


    public AddressBook getBookObj(BookFilter filter)
    {
        GenericQuery query  = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getDeptName()))
            query.append(" and obj.deptName =:deptName").setParam("deptName",filter.getDeptName());
       // if(StringUtils.isNotBlank(filter.getDeptCode()))
            query.append(" and obj.deptCode=:deptCode ").setParam("deptCode",filter.getDeptCode());
        if(StringUtils.isNotBlank(filter.getDeptType()))
            query.append(" and obj.deptType =:deptType").setParam("deptType",filter.getDeptType());

        return  query.singleResult();
    }
}
